﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.BlackApart.Business.Reservations;
using blackhouse.BlackApart.Business;

namespace blackhouse.BlackApart.Actions {
    public abstract class ReservationAction : Action {

        #region Fields

        private int reservationId;
        private IWebReservation reservation;
        private int initialStatusId;
        protected string[] initialData;

        #endregion

        #region Methods

        protected abstract void RunForReservation(int reservationId, int initialStatusId);

        public override void Initialize(string initializeData) {
            if (!string.IsNullOrEmpty(initializeData)) {
                string[] parts = initializeData.Split(',');
                if (parts.Length >= 2) {
                    Int32.TryParse(parts[0], out this.reservationId);
                    Int32.TryParse(parts[1], out this.initialStatusId);
                    initialData = new string[parts.Length - 2];
                    Array.Copy(parts, 2, initialData, 0, parts.Length - 2);
                }
            }
        }

        public override void Run() {
            this.Log.AppendToMessage("Reservation ID: " + this.reservationId);
            this.Log.AppendToMessage("Initial status: " + this.initialStatusId);
            this.RunForReservation(this.reservationId, this.initialStatusId);
        }

        protected IWebReservation GetReservation() {
            if (reservation == null && reservationId > 0)
                this.reservation = Factory.Instance().GetWebReservation(this.reservationId);
            return this.reservation;
        }

        #endregion

    }
}
